//
//  MovieImageView.m
//  Movie
//
//  Created by cjy on 16/3/23.
//  Copyright © 2016年 HY. All rights reserved.
//

#import "MovieImageView.h"
#import "MovieModel.h"
#import "MovieContentView.h"
@implementation MovieImageView

- (instancetype)initWithFrame:(CGRect)frame width:(CGFloat)width model:(MovieModel *)model collor:(UIColor *)collor{


    self = [super initWithFrame:frame];
    
    if (self) {
        

        // 子视图超出边界就会被剪掉
        self.clipsToBounds = YES;

        _picture = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height/1.7)];
        
        //UIImageView 的contentMode这个属性是用来设置图片的显示方式，如居中、居右，是否缩放等
        _picture.contentMode = UIViewContentModeScaleAspectFill;

        [self addSubview:_picture];
        _picture.userInteractionEnabled = YES;
        
        
    }

    return self;


}

- (void)imageOffset{

    
    //坐标转换
    // 相对于 window 的位置计算出 x , y 值
    CGRect centerToWindow = [self convertRect:self.bounds toView:nil];
    
    CGFloat centerX = CGRectGetMidX(centerToWindow);
    CGPoint windowCenter = self.window.center;
    
    CGFloat cellOffsetX = centerX - windowCenter.x;
    
    CGFloat offsetDig =  cellOffsetX / self.window.frame.size.height *2;
    
    CGAffineTransform transX = CGAffineTransformMakeTranslation(- offsetDig * [UIScreen mainScreen].bounds.size.width * 0.7, 0);
    
    self.picture.transform = transX;




}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
